import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { RequestService } from './request.service';
import { Brief, BriefParam } from './../model/brief';
import { Injectable } from '@angular/core';
import { CommonApi } from './commonApi';

@Injectable()
export class BirefApiService extends CommonApi<BriefParam>{

  constructor(
    private request: RequestService
  ) {
    super(request, '/taskBrief');
  }

  getListByPhaseTaskId(taskId: number): Observable<Array<Brief>> {
    const url = this.baseUrl + '/listByPhaseTaskId/' + taskId;
    return this.request.get<Array<BriefParam>>(url).pipe(
      map(
        params => {
          return params.map(param => new Brief(param));
        }
      ),
    );
  }

  getListByPeriodTaskId(taskId: number): Observable<Array<Brief>> {
    const url = this.baseUrl + '/listByPeriodicTaskId/' + taskId;
    return this.request.get<Array<BriefParam>>(url).pipe(
      map(
        params => {
          return params.map(param => new Brief(param));
        }
      ),
    );
  }
}
